package org.doubango.imsdroid.Screens;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;

import org.doubango.imsdroid.Engine;
import org.doubango.imsdroid.R;
import org.doubango.imsdroid.Services.IScreenService;
import org.doubango.ngn.services.INgnSipService;

/**
 * Created by TaZ on 2017/11/4.
 */

public class MainScreen extends TabActivity implements IBaseScreen {
    private static String TAG = MainScreen.class.getCanonicalName();

    private TabHost tabhost;
    private RadioGroup main_radiogroup;

    private IScreenService mScreenService;
    private final INgnSipService mSipService;

    private RadioButton txt_call;
    private RadioButton txt_message;
    private RadioButton txt_list;
    private RadioButton txt_add;
    private RadioButton txt_settings;

    public MainScreen() {
        mScreenService = ((Engine)Engine.getInstance()).getScreenService();
        mSipService = Engine.getInstance().getSipService();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        main_radiogroup = (RadioGroup) findViewById(R.id.main_radiogroup);
        txt_call = (RadioButton)findViewById(R.id.txt_call);
        txt_message = (RadioButton)findViewById(R.id.txt_msg);
        txt_list = (RadioButton)findViewById(R.id.txt_list);
        txt_add = (RadioButton)findViewById(R.id.txt_soft);
        txt_settings = (RadioButton)findViewById(R.id.txt_settings);

        tabhost = getTabHost();
        tabhost.addTab(tabhost.newTabSpec("tag1").setIndicator("0").
                setContent(new Intent(MainScreen.this, ScreenTabDialer.class)));
        tabhost.addTab(tabhost.newTabSpec("tag2").setIndicator("1").
                setContent(new Intent(MainScreen.this, ScreenTabMessages.class)));
        tabhost.addTab(tabhost.newTabSpec("tag3").setIndicator("2").
                setContent(new Intent(MainScreen.this, ScreenTabContacts.class)));
        tabhost.addTab(tabhost.newTabSpec("tag4").setIndicator("3").
                setContent(new Intent(MainScreen.this, ScreenQoS.class)));
        tabhost.addTab(tabhost.newTabSpec("tag5").setIndicator("4").
                setContent(new Intent(MainScreen.this, ScreenSettings.class)));

        CheckListener checkradio = new CheckListener();
        main_radiogroup.setOnCheckedChangeListener(checkradio);

    }

    @Override
    public String getId() {
        return TAG;
    }

    @Override
    public BaseScreen.SCREEN_TYPE getType() {
        return BaseScreen.SCREEN_TYPE.MAIN_SCREEN_T;
    }

    @Override
    public boolean hasMenu() {
        return false;
    }

    @Override
    public boolean hasBack() {
        return false;
    }

    @Override
    public boolean back() {
        return mScreenService.back();
    }

    @Override
    public boolean createOptionsMenu(Menu menu) {
        return false;
    }

    public class CheckListener implements RadioGroup.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            switch(checkedId){
                case R.id.txt_call:
                    tabhost.setCurrentTab(0);
                    break;
                case R.id.txt_msg:
                    tabhost.setCurrentTab(1);
                    break;
                case R.id.txt_list:
                    tabhost.setCurrentTab(2);
                    break;
                case R.id.txt_soft:
                    tabhost.setCurrentTab(3);
                    break;
                case R.id.txt_settings:
                    tabhost.setCurrentTab(4);
                    break;
            }


        }
    }
}
